package com.musicrun.midi
{
	public class Track
	{
		/**
		 * Maps time position to the note
		 * that start at that time.
		 */
		private var notesByTime:Array;
		
		var channelNumber;
		
		public function Track()
		{
			this.notesByTime = new Array();
		}
		
		public function addNote(note:Note, time:int):void
		{
			notesByTime[time] = note;
		}
		
		/**
		 * If as note exists at this time position, return that note,
		 * otherwise return null.
		 **/
		public function getNote(time:int):Note 
		{
			if (notesByTime[time] == undefined)
				return null;
			else
				return notesByTime[time];
		}
		
		public function setChannelNumber(channelNumber:int):void
		{
			this.channelNumber = channelNumber;
		}
		
		public function toString():String 
		{
			var retString:String = "Track " + channelNumber + "\n";
			for each (var note:Note in notesByTime) {
				retString += ("    " + note + "\n");
			}
			return retString;
		}
	}
}